<template>
    <div class="edit_page_div" style="width: 700px; margin-top: 20px;">
        <el-form ref="form" :model="form" :rules="rules" :show-message="false" label-width="100px">
            <el-form-item label="存放路径" prop="filePath">
                <el-input v-model="form.filePath" placeholder="D:/content/codeModel/" style="width: 600px;"></el-input>
            </el-form-item>
            <el-form-item label="包路径" prop="projectPath">
                <el-input v-model="form.projectPath" placeholder="com.project" style="width: 600px;"></el-input>
            </el-form-item>
            <el-form-item label="业务包" prop="folderName">
                <el-input v-model="form.folderName" placeholder="module.system" style="width: 600px;"></el-input>
            </el-form-item>
            <el-form-item label="数据库名" prop="tableSchema">
                <el-input v-model="form.tableSchema" placeholder="base_config" style="width: 600px;"></el-input>
            </el-form-item>
            <el-form-item label="库注释" prop="libraryComment">
                <el-input v-model="form.libraryComment" placeholder="系统管理" style="width: 600px;"></el-input>
            </el-form-item>
            <el-form-item label="表名" prop="tableNames">
                <el-input v-model="form.tableNames" placeholder="多个表用','分隔，base_constant,base_api"
                          style="width: 600px;"></el-input>
            </el-form-item>
        </el-form>
        <div class="edit_button">
            <el-button v-loading.fullscreen.lock="loading" type="primary" @click="submit">生成代码</el-button>
        </div>
    </div>
</template>

<script>
import CheckboxOption from "@/components/checkbox/checkboxOption";

export default {
    name: "generateEdit",
    // eslint-disable-next-line vue/no-unused-components
    components: {CheckboxOption},
    props: {
        visible: Boolean,
        id: String,
    },
    data() {
        return {
            loading: false,
            checkAll: false,
            form: {
                filePath: 'D:/content/codeModel/',
                projectPath: 'com.project',
                folderName: 'module',
                tableSchema: '',
                libraryComment: '',
                tableNames: '',
            },
            rules: {
                filePath: [{required: true, message: '', trigger: 'change'}],
                projectPath: [{required: true, message: '', trigger: 'change'}],
                folderName: [{required: true, message: '', trigger: 'change'}],
                tableSchema: [{required: true, message: '', trigger: 'change'}],
                libraryComment: [{required: true, message: '', trigger: 'change'}],
                tableNames: [{required: false, message: '', trigger: 'change'}],
            }
        }
    },
    methods: {
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.loading = true;
                    this.$axios.post("/CHILD_SYSTEM/generate/createModel", this.form).then(res => {
                        this.$message.success(res.message);
                    }).finally(() => {
                        this.loading = false;
                    })
                } else {
                    this.$message.error('表单填写有误');
                    return false;
                }
            });
        },
    }
}
</script>

<style scoped>

</style>